$(document).ready(function () {
    App.init();
    TableManageFixedHeader.init();

    $('.datepicker-default').datepicker({
        language: 'zh-CN',//显示中文
        format: 'yyyy-mm-dd',//显示格式
        minView: "month",//设置只显示到月份
        initialDate: new Date(),//初始化当前日期
        autoclose: true,//选中自动关闭
        todayBtn: 'linked'//显示今日按钮
    });

    wrapTable1();
    wrapTable2();


    $("#menuInfos li").removeClass("active");
    $("#menuInfos li").removeClass("expand");
    $("#homeLi").addClass("active");
});

//分页展示
var table1;
var table2;
function wrapTable1() {
    table1 = $("#modeltable").DataTable({
        "bAutoWidth": false,
        "order": [[0, 'desc']],
        "pagingType": "simple_numbers",//设置分页控件的模式
        searching: false,//屏蔽datatales的查询框
        aLengthMenu: [15],//设置一页展示10条记录
        "ordering":false,
        "bLengthChange": false,//屏蔽tables的一页展示多少条记录的下拉列表
        "oLanguage": {  //对表格国际化
            "sLengthMenu": "每页显示 _MENU_条",
            "sZeroRecords": "没有找到符合条件的数据",
            "sInfo": "当前第 _START_ - _END_ 条　共计 _TOTAL_ 条",
            "sInfoEmpty": "没有记录",
            "sInfoFiltered": "(从 _MAX_ 条记录中过滤)",
            "sSearch": "搜索：",
            "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "前一页",
                "sNext": "后一页",
                "sLast": "尾页"
            }
        },
        "processing": true, //打开数据加载时的等待效果
        "serverSide": true,//打开后台分页
        "ajax": {
            "url": "/task/queryTableData",
            "dataSrc": "aaData",
            "data": function (params) {
                params.status = '1,3';
            }
        },
        "columns": [
            {
                "render": function (data, type, row, meta) {
                    return meta.row + 1;
                }
            },
            {"data": "name"},
            {"data": "submitAt"},
            {
                "data": "submitUser.realName",
                "render": function(data, type, row, meta) {
                    return row.submitUser.realName +'(' + row.submitUser.roleName+ ')';
                },
                "bSortable": false
            }
        ],

        "columnDefs": [{
            "targets": 4,//是操作按钮目标列
            "data": null,
            "render": function (data, type) {
                if (data.status === 1) {
                    return  "<a href='" + data.url + "' class='btn-link'>审核</a>&nbsp;&nbsp;&nbsp;&nbsp;";

                } else if (data.status === 3) {
                    return  "<a href='" + data.url + "&taskId="+ data.tid + "' onclick='doneTask(" + data.tid + ")' class='btn-link'>查看</a>&nbsp;&nbsp;&nbsp;&nbsp;";
                } else {
                    return '';
                }
            }
        }]
    });

}

function wrapTable2() {
    table2 = $("#modeltable2").DataTable({
        "bAutoWidth": false,
        "order": [[0, 'desc']],
        "pagingType": "simple_numbers",//设置分页控件的模式
        searching: false,//屏蔽datatales的查询框
        aLengthMenu: [15],//设置一页展示10条记录
        "ordering":false,
        "bLengthChange": false,//屏蔽tables的一页展示多少条记录的下拉列表
        "oLanguage": {  //对表格国际化
            "sLengthMenu": "每页显示 _MENU_条",
            "sZeroRecords": "没有找到符合条件的数据",
            "sInfo": "当前第 _START_ - _END_ 条　共计 _TOTAL_ 条",
            "sInfoEmpty": "没有记录",
            "sInfoFiltered": "(从 _MAX_ 条记录中过滤)",
            "sSearch": "搜索：",
            "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "前一页",
                "sNext": "后一页",
                "sLast": "尾页"
            }
        },
        "processing": true, //打开数据加载时的等待效果
        "serverSide": true,//打开后台分页
        "ajax": {
            "url": "/task/queryTableData",
            "dataSrc": "aaData",
            "data": function (params) {
                params.status = 2;
            }
        },
        "columns": [
            {
                "render": function(data, type, row, meta) {
                    return meta.row + 1;
                }
            },
            {
                "data": "name",
                "render": function (data, type, row, meta) {

                    return "<a href='/channel/tolist/P?nodeId=1&businessId="+ row.businessId + "' class='btn-link'>" + data + "</a>&nbsp;&nbsp;&nbsp;&nbsp;";

                }
            },
            {
                "render": function(data, type, row, meta) {
                    return row.submitUser.realName +'(' + row.submitUser.roleName+ ')';
                },
                "bSortable": false
            },
            {
                "data": "submitAt"
            },
            {"data": "auditAt"},
            {
                "render": function(data, type, row, meta) {
                    return row.auditUser.realName +'(' + row.auditUser.roleName+ ')';
                },
                "bSortable": false
            }
        ]

    });

}


function doneTask(tid) {

    var url = '/task/view_done/' + tid;
    $.get(url, function(data) {
        console.log(111);
    })

}

//去往编辑页面
function toedit(id) {
    alert(id);
    window.location.href = "/re/tocheck/" + id;
}

function toDetail(row) {
    var objectId = $(row).closest('tr').find('td').eq(0).text();

    window.location.href= "/report/company/2/" + objectId;
}


// 展示待办
function showTodo() {
    table1.ajax.reload();


}

// 展示已办
function showDone() {
    table2.ajax.reload();
}

